home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Dev
/
misc
/
LOCCounter.lha
/
LOCCounter
/
src
/
Tally.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-08-18
|
2KB
|
120 lines
/****************************************************************************
*
* $RCSfile: Tally.cpp $
* $Revision: 2.14 $
* $Date: 2004/08/17 23:02:55 $
* $Author: ssolie $
*
*****************************************************************************
*
* Copyright (c) 2004 Steven Solie. All Rights Reserved.
*
*****************************************************************************
*
* Tally.cpp -- Tally component
*
* The Tally class is used to tally the results of lines of code counting
* and the print the results in a report.
*/
#include "Tally.h"
#include "FileCount.h"
#include "FileTally.h"
#include <proto/dos.h>
#include <algorithm>
#include <boost/bind.hpp>
namespace {
typedef boost::shared_ptr<FileTally> FileTallyPtr;
class Comparator {
public:
bool operator ()(const FileTallyPtr& lhs, const FileTallyPtr& rhs) const;
};
bool Comparator::operator ()(const FileTallyPtr& lhs,
const FileTallyPtr& rhs) const
{
return *lhs < *rhs;
}
};
Tally::Tally(bool diff_mode) :
m_num_files(0),
m_total_loc(0),
m_total_added_loc(0),
m_total_deleted_loc(0),
m_diff_mode(diff_mode)
{
}
Tally::~Tally()
{
}
void Tally::addFile(FileCount& fc)
{
if ( m_diff_mode ) {
FileTallyPtr file(new FileTally(fc.getName(), fc.getAddedCount(),
fc.getDeletedCount()));
m_files.push_back(file);
m_total_added_loc += fc.getAddedCount();
m_total_deleted_loc += fc.getDeletedCount();
}
else {
FileTallyPtr file(new FileTally(fc.getName(), fc.getCount()));
m_files.push_back(file);
m_total_loc += fc.getCount();
}
++m_num_files;
}
void Tally::print(const BPTR fh)
{
m_files.sort(Comparator());
std::for_each(m_files.begin(), m_files.end(),
boost::bind(&FileTally::print, _1, fh));
if ( m_num_files > 1 ) {
IDOS->FPrintf(fh, "\n");
printTotal(fh);
}
}
void Tally::printTotal(const BPTR fh) const
{
if ( m_diff_mode ) {
IDOS->FPrintf(fh, "%8lu Total added LOC\n", m_total_added_loc);
IDOS->FPrintf(fh, "%8lu Total deleted LOC\n", m_total_deleted_loc);
}
else {
IDOS->FPrintf(fh, "%8lu Total LOC\n", m_total_loc);
}
}
void Tally::printQuick(const BPTR fh) const
{
if ( m_diff_mode ) {
IDOS->FPrintf(fh, "0");
}
else {
IDOS->FPrintf(fh, "%lu", m_total_loc);
}
}